package com.bugbuff.dubbo.server.controller;

import cn.hutool.core.util.ObjectUtil;
import com.bugbuff.dubbo.server.service.HomePageService;
import com.bugbuff.dubbo.server.vo.AddUsersVo;
import com.bugbuff.dubbo.server.vo.DistributionVo;
import com.bugbuff.dubbo.server.vo.StatisticalVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("management/dashboard")
public class WhiteBoardController {

    @Autowired
    private HomePageService homePageService;

/*
    *//**
     * 概要统计信息
     * @return
     *//*
    @GetMapping("summary")
    public ResponseEntity<StatisticalVo> summary(){

        try {
            StatisticalVo summaryVo=this.homePageService.summary();

            //对返回的summaryVo对象进行非空判断
            if (ObjectUtil.isNotEmpty(summaryVo)) {
                //不是空,返回summaryVo对象给前端
                return ResponseEntity.ok(summaryVo);
            }
        } catch (Exception e) {
            log.error("查询概要统计信息出错..."+e);
        }

        //返回500
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }*/




    /**
     * 注册用户分布，行业top、年龄、性别、地区
     * @return
     */
    @GetMapping("distribution")
    public ResponseEntity<DistributionVo> distribution(@RequestParam("sd") Long startDate,
                                                       @RequestParam("ed") Long endDate){


        try {

            DistributionVo distributionVo=  this.homePageService.distribution(startDate,endDate);

            //对distributionVo进行非空判断
            if (ObjectUtil.isNotEmpty(distributionVo)) {

                //如果不是空,将distributionVo返回给前端
                return ResponseEntity.ok(distributionVo);
            }
        } catch (Exception e) {
            log.error("查询注册用户分布，行业top、年龄、性别、地区信息出错了..."+e);
        }

        //返回500
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();


    }

    /**
     * 新增、活跃用户、次日留存率
     * @return
     */
    @GetMapping("users")
    public ResponseEntity<AddUsersVo> AddUserData(@RequestParam("sd") Long startDate,
                                                  @RequestParam("ed") Long endDate,
                                                  @RequestParam("type")Integer type){
        try {

            AddUsersVo addUsersVo=  this.homePageService.AddUserData(startDate,endDate,type);

            //对distributionVo进行非空判断
            if (ObjectUtil.isNotEmpty(addUsersVo)) {

                //如果不是空,将distributionVo返回给前端
                return ResponseEntity.ok(addUsersVo);
            }
        } catch (Exception e) {
            log.error("查询新增、活跃用户、次日留存率信息出错..."+e);
        }

        //返回500
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();


    }

}

